//var express = require('express')
//var path = require('path')  //引入js库的路径
//var port = process.env.PORT || 3000
//var app = express()
//
//app.set('views', './views/pages')  //设置视图根目录
//app.set('view engine', 'jade') //设置默认模板引擎
//app.use(require('body-parser').urlencoded({extended: true}))
//app.use(express.static(path.join(__dirname, '/bower_components')))  //jq路径
//app.listen(port) //监听端口

var express = require("express")//这里主要是引用所必须要的模块，当然，这些模块是需要使用"npm install 模块名"安装的
var bodyParser = require('body-parser')
var port = process.env.PORT || 3000
var app = express()

app.set('views', './views/pages')//定义了一些路径和所用到的引擎
app.set('view engine', 'jade')
app.use(bodyParser.urlencoded({extended: true}))
//app.use(require('body-parser').urlencoded({extended: true}))
// app.use(express.static(path.join(__dirname,'bower_components')))
app.use(express.static(__dirname + '/views'));
app.use('/bower_components', express.static(__dirname + '/bower_components'));
app.listen(port);

console.log('imooc started on port' + port)

//index page 路由首页
app.get('/', function(req, res){
	res.render('index', {
		title : 'imooc 首页',
		movies: [{
		   title: '机械1',
           _id: 1,
           poster: 'https://www.baidu.com/'		   
		},{
		   title: '机械2',
           _id: 2,
           poster: 'https://www.baidu.com/'		   
		},{
		   title: '机械3',
           _id: 3,
           poster: 'https://www.baidu.com/'		   
		},{
		   title: '机械4',
           _id: 4,
           poster: 'https://www.baidu.com/'		   
		},{
		   title: '机械5',
           _id: 5,
           poster: 'https://www.baidu.com/'		   
		}]
	})
})

app.get('/movie/:id', function(req, res){
	res.render('detail', {
		title : 'imooc 详情页',
		movie: {
		  doctor: '何在吸收的的的',
          country: '美国',
          title: '机械战警',
          year: '2014',
          poster: 'https://www.baidu.com/',
          language: '英语',
          flash: 'http://player.youku.com/player.php/sid/XMTgwOTc5Nzc4MA==/v.swf',
          summary: '的顶顶顶顶顶大多数的所得到的福特瑞特让他人，的顶顶顶顶顶大多数的所得到的福特瑞特让他人的顶顶顶顶顶大多数的所得到的福特瑞特让他人的顶顶顶顶顶大多数的所得到的福特瑞特让他人的顶顶顶顶顶大多数的所得到的福特瑞特让他人的顶顶顶顶顶大多数的所得到的福特瑞特让他人'		  
		}
	})
})

app.get('/admin/movie', function(req, res){
	res.render('admin', {
		title : 'imooc 后台页',
		movie: {
		  title: '',
          doctor: '',
          country: '',
          year: '',
          poster: '',
          flash: '',
          summary: '',		
          language: ''		  
		}
	})
})

app.get('/admin/list', function(req, res){
	res.render('list', {
		title : 'imooc 列表页',
		movies: {
		  title: '机械战警',
          _id: 1,		  
		  doctor: '何在吸收的的的',
          country: '美国',
          year: '2014',
          language: '英语',
          flash: 'http://player.youku.com/player.php/sid/XMTgwOTc5Nzc4MA==/v.swf'		  
		}
	})
})

